home *** CD-ROM | disk | FTP | other *** search
- /*
- A very simple echo udp client.
- Shows how to use an UDP service.
- To test it on localhost, be sure echo/UDP service is enabled
- in services and inted database.
- rx echoudp localhost
- */
-
- if ~open("STDERR","*","W") then STDERR="STDOUT"
-
- l="rmh.library";if ~show("L",l) then;if ~addlib(l,0,-30) then exit
- prg=ProgramName("NOEXT")
- if AddLibrary("rexxsupport.library","rxsocket.library")~=0 then
- call err "can't find" result,1
-
- if ~RMH_ReadArgs("HOST/A") then do
- call PrintFault(IoErr(),prg)
- exit
- end
-
- addr = resolve(parm.0.value)
- if addr=="-1" then call err "no host <"parm.0.value">",1
-
- if ~getservbyname("SE","echo","udp") then
- call err "echo tcp service not found"
-
- remote.addrFamily = "INET"
- remote.addrAddr = addr
- remote.addrPort = se.servPort
-
- sock = socket("INET","DGRAM","IP")
- if sock<0 then call err "no socket"
-
- local.addrFamily = "INET"
- local.addrAddr = 0
- local.addrPort = 0
- /*if bind(sock,"LOCAL")<0 then call err "bind error"*/
-
- data = "echo udp service test"
- n = SendTo(sock,data,0,"REMOTE")
- if n<length(data) then call err "sendto error"
-
- len = RecvFrom(sock,"BUF",256,0,"REMOTE")
- if len<0 then call err "recvfrom error"
-
- say buf
- call CloseSocket(sock)
- exit
-
- err:
- parse arg msg,noerr
- if noerr~=1 then do
- es="("ErrorString(Errno())")"
- end
- else es=""
- call Writeln(STDERR,prg": "msg es)
- exit
-